<% if has_role?(:admin) && configuring? %>
<div class="admin">
  <table class="spaced">
      <% addeable_columns = components_configuration.addeable_columns %>
     <% if addeable_columns.size > 0 %>
    <tr>
	<td colspan="2"><%= image_tag 'warning.png' %> <%= message('components.note_changes_impact_all_users') -%></td>
	</tr>
    <tr>
      <td width="1%" nowrap><%= message('add_a_column') -%></td>
      <td>
        <form action="<%= url_for :controller => "columns", :action => "add" -%>" >
          <input type="hidden" name="rid" value="<%= @resource.id if @resource %>" />
          <select name="id" onchange="$j('#add_column_loading').show();submit();" id="select_add_column">
            <option value=""></option>
            <% addeable_columns.keys.sort.each do |domain| %>
              <optgroup label="<%= domain %>">
                <% addeable_columns[domain].each do |column| %>
                  <option value="<%= column.id -%>"><%= column.name %></option>
                <% end %>
              </optgroup>
            <% end %>
          </select>
          <%= image_tag 'loading.gif', :style => 'display: none;', :id => 'add_column_loading' %>
          <script>
            $j(function() {
              $j('#select_add_column').select2({
                width: '300px',
                placeholder: '<%= escape_javascript message('select_a_metric') -%>'
              });
            });
          </script>
        </form>
      </td>
    </tr>
    <% end %>
    <tr>
      <td width="1%" nowrap><%= message('default_sort_on') -%> </td>
      <td>
        <form action="<%= url_for :controller => "columns", :action => "default_sorting" -%>">
          <input type="hidden" name="rid" value="<%= @resource.id if @resource %>" />
          <select name="id" onchange="$j('#sort_column_loading').show();submit();" id="select_default_sorting">
	        <option value="project" <%= 'selected' if components_configuration.sorted_by_project_name? -%>><%= message('project_name') -%></option>
            <% configured_columns.sort_by{|col| col.name}.each do |column| 
                if column.sortable? %>
                <option value="<%= column.id -%>" <%= 'selected' if column.sort_default? -%>><%= column.name %></option>
            <% end
            end %>
          </select>
          <%= image_tag 'loading.gif', :style => 'display: none;', :id => 'sort_column_loading' %>
          <script>
            $j(function() {
              $j('#select_default_sorting').select2({ width: '150px' });
            });
          </script>
        </form>
      </td>
    </tr>
  </table>
</div>
<% end %>
